﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Medianamik.Core.Cache;
using Medianamik.Core.Action;
using Medianamik.Core;
using System.Web;
using System.Web.Caching;


namespace Medianamik.Client.Cache
{
    public abstract class CacheManager<managerType> : CacheManagerBase<managerType>
        where managerType : CacheManager<managerType>, new()
    {

        private static readonly string _typeName = new managerType().GetType().Name;
       
        private int? _currentGeneration;
        protected virtual int CurrentGeneration
        {
            get
            {
                return _currentGeneration
                    ?? (_currentGeneration = new Utility().GetGeneration(HttpContext.Current.Request)).Value; 
            }
        }

        protected override string CacheKeyPrefix
        {
            get
            {
                return _typeName;
            }
        }

        protected override string AlterCacheKey(string pCacheKey)
        {
            return pCacheKey + Thread.CurrentThread.CurrentUICulture.Name + CurrentGeneration;
        }

    }
}
